package com.study.ws.config.redis.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.messaging.simp.SimpMessagingTemplate;

/**
 * @author xl-9527
 * @since 2025/3/28
 **/
public class RedisListener implements MessageListener {

    private final Logger log = LoggerFactory.getLogger(RedisListener.class);

    private final SimpMessagingTemplate simpMessagingTemplate;

    public RedisListener(final SimpMessagingTemplate simpMessagingTemplate) {
        this.simpMessagingTemplate = simpMessagingTemplate;
    }

    @Override
    public void onMessage(final Message message, final byte[] pattern) {
        log.info("receive msg：{} from redis", new String(message.getBody()));
        simpMessagingTemplate.convertAndSendToUser("1", "/test", "system: i receive message -> [" + message + "]");
    }
}
